package com.ruoyi.finance.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.finance.domain.*;
import com.ruoyi.finance.domain.response.*;
import com.ruoyi.finance.enums.AttachmentRelationTypeEnum;
import com.ruoyi.finance.enums.AttachmentTypeEnum;
import com.ruoyi.finance.enums.FinanceProductTypeEnum;
import com.ruoyi.finance.service.financeCheckService;
import com.ruoyi.finance.utils.MyJinRongUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

/**
 * @return name
 */
@RestController
@RequestMapping("financeCheck")
public class financeCheckController {
    @Autowired
    private financeCheckService service;

    @PreAuthorize(hasPermi = "finance:financeCheck:list")
    @RequestMapping("list")
    public PageInfo<JrRentInstallmentResponseDto> listAll(TJrquery tJrquery){
        System.out.println("数据信息"+tJrquery);
        PageHelper.startPage(tJrquery.getPageNum(),tJrquery.getPageSize());
        List<JrRentInstallmentResponseDto> list = service.listAll(tJrquery);
        return new PageInfo<>(list);
    }

    @PreAuthorize(hasPermi = "finance:financeCheck:list")
    @RequestMapping("listshenhe")
    public JrRentInstallmentResponseDto listshenhe(String id){
        System.out.println("信息审核++++++++++++++++++++"+id);
        JrRentInstallmentResponseDto listshenhe = service.listshenhe(id);
        return listshenhe;
    }


    @PreAuthorize(hasPermi = "finance:financeCheck:update")
    @RequestMapping("updateapply_state")
    public boolean updateapply_state(String id,String apply_state){
        System.out.println("信息审核++++++++++++++++++++"+id+"+++++++++"+apply_state);
        boolean b = service.updateapply_state(id,apply_state);
        return b;

    }



//    @PreAuthorize(hasPermi = "finance:financeCheck:list")
//    @RequestMapping("listshenhe")
//    public Object listshenhe(String id,String cf_contract_id,String jr_product_type,String apply_state,String loginUserId) {
//        System.out.println("审核列表信息id" + id);
//        System.out.println("审核信息类型" + jr_product_type);
//        System.out.println("审核信息状态" + apply_state);
//        System.out.println("审核信息出房合同id" + cf_contract_id);
//        ModelAndView mv = new ModelAndView();
//        Long businessId = null;
//        // 金融产品通过jrProductType判断 跳转不同页面：   1:租房分期  2:收房贷  3:应收租约保理
//        if (Integer.parseInt(jr_product_type) == FinanceProductTypeEnum.RENTMENT.getIndex()) {
////            // 跳转租房分期页面
////            mv = ModelAndViewUtil.of("jinrong/jumpHouse");
//            //租房分期详细信息
//            JrRentInstallmentDetailsResponseDto installment = service.selectInstallmentDetails(id);
//            businessId = installment.getBussinessId();
//
//            // 获取租客信息基本信息
//            ResponseDetailCfContractDto contractDetail = service.detailCfContract(cf_contract_id);
//            // 获取待收租金合计   还款账期*月租金= 待收租金合计
//            BigDecimal totalMonthLimit = BigDecimal.ZERO;
//            BigDecimal monthRent = contractDetail.getMonthRent();
//            Integer monthLimit = installment.getMonthLimit();
//            // 计算利息
//            totalMonthLimit = monthRent.multiply(new BigDecimal(monthLimit));
//            // 利息 =应收租约合计* 租客承担比例 / 年化率  * 期数
//            // 应收租约合计
//            double reLeaseCount = Double.valueOf(installment.getReLeaseCount()).doubleValue();
//            // 调用计算公式
//            double periods = installment.getMonthLimit();
//            //租客承担比例
//            double tenantRate = MyJinRongUtils.div(installment.getTenantRate().doubleValue(), 100, 2);// 利率
//            // 公寓分期利息合计
//            double inInterestCount = Double.valueOf(installment.getInInterestCount()).doubleValue();
//            // 计算利息
//            double mul = MyJinRongUtils.mul(reLeaseCount, tenantRate);
//            double div = MyJinRongUtils.div(mul, 12, 2);
//            double rateCount_ = MyJinRongUtils.mul(div, periods);
//            double rateCount = MyJinRongUtils.add(rateCount_, inInterestCount);
//
//            // 月租金
//
//            //租客合同url
//            List<JrUrlResponseDto> contractUrl = service.selectAttachementUrlList(AttachmentTypeEnum.ZLHT.getIndex(), Long.parseLong(cf_contract_id), AttachmentRelationTypeEnum.CFHT.getIndex());
//            // 客户身份证复印件
//            List<JrUrlResponseDto> cardurl = service.selectAttachementUrlList(AttachmentTypeEnum.KHSFZ.getIndex(), Long.parseLong(cf_contract_id), AttachmentRelationTypeEnum.CFHT.getIndex());
//
//            mv.addObject("contractDetail", contractDetail);
//            mv.addObject("totalMonthLimit", totalMonthLimit);
//            mv.addObject("contractUrl", contractUrl);
//            mv.addObject("cardurl", cardurl);
//            mv.addObject("installment", installment);
//            mv.addObject("rateCount", rateCount);
//
//        } else if (Integer.parseInt(jr_product_type) == FinanceProductTypeEnum.SFLOAN.getIndex()) {
//            // 跳转收房贷页面
////            mv = ModelAndViewUtil.of("jinrong/jumpRecieve");
//
//            // 获取收房贷详细信息
//            JrSfLoanDetailsResponseDto sfLoanDetail = service.selectSfLoanDetails(id);
//            businessId = sfLoanDetail.getBusinessId();
//            // 获取租客信息基本信息
//            ResponseDetailSfContractDto contractDetail = service.detailSfContract(cf_contract_id);
//            // 计算租房分期  周期还款金额     收款方式的y * 月租金 =  周期还款金额
//            BigDecimal cycleAmount1 = BigDecimal.ZERO;
//            //收款方式（押X付Y的Y）
//            Integer paymentType = contractDetail.getPaymentType();
//            // 承租月租金
//            // 周期还款金额  = 还款总额合计 /期数  rp_amount_count/month_limit
//            String rpAmountCount = sfLoanDetail.getRpAmountCount();
//
//            double parseDouble = Double.parseDouble(rpAmountCount);
//
//            double cycleAmount = MyJinRongUtils.div(parseDouble, sfLoanDetail.getMonthLimit(), 2);
//
//            //	BigDecimal monthRent = contractDetail.getMonthRent();
//            //	cycleAmount = monthRent.multiply(new BigDecimal(paymentType));
//            // 查询租客户身份证复印件url
//            List<JrUrlResponseDto> sfCardsUrl = service.selectAttachementUrlList(AttachmentTypeEnum.YZSFZ.getIndex(), Long.parseLong(cf_contract_id), AttachmentRelationTypeEnum.SFHT.getIndex());
//            // 查询收房贷合同url
//            List<JrUrlResponseDto> sfDContractUrl = service.selectAttachementUrlList(AttachmentTypeEnum.SFHT.getIndex(), Long.parseLong(cf_contract_id), AttachmentRelationTypeEnum.SFHT.getIndex());
//            // 查询收房贷房产证url
//            List<JrUrlResponseDto> sfDHouse = service.selectAttachementUrlList(AttachmentTypeEnum.FCZ.getIndex(), Long.parseLong(cf_contract_id), AttachmentRelationTypeEnum.SFHT.getIndex());
//            // 查询收房贷业主银行卡url
//            List<JrUrlResponseDto> sfDBank = service.selectAttachementUrlList(AttachmentTypeEnum.YHKXX.getIndex(), Long.parseLong(cf_contract_id), AttachmentRelationTypeEnum.SFHT.getIndex());
//
//            mv.addObject("sfLoanDetail", sfLoanDetail);
//            mv.addObject("cycleAmount", cycleAmount);
//            mv.addObject("contractDetail", contractDetail);
//            mv.addObject("sfCardsUrl", sfCardsUrl);
//            mv.addObject("sfDContractUrl", sfDContractUrl);
//            mv.addObject("sfDHouse", sfDHouse);
//            mv.addObject("sfDBank", sfDBank);
//
//        } else {
//            // 跳转租约保理页面
////            mv = ModelAndViewUtil.of("jinrong/jumpProtect");
//            // 租约保理申请详细信息
//            List<JrFactoringDetailsResponseDto> factoringDetails = service.selectFactoringDetails(id);
//            // 租约保理申请查询
//            JrFactoringEntity jrFactoring = service.selectFactoring(id);
//            businessId = jrFactoring.getBusinessId();
//
//            mv.addObject("factoringDetails", factoringDetails);
//            mv.addObject("jrFactoring", jrFactoring);
//            //租约保理详细信息
//        }
//        // 基本信息加载
//        ResponseDetailCompanyInfoDto detail = service.detailCompanyInfo(businessId);
//
//        // 获取账户类型
//        ResponseUpdateBankInfoDto bankInfo = service.queryBankInfo(businessId);
//        // 获取用户名  手机号
////        SysUserEntity sysUser = service.queryObject(loginUserId);
//
//        mv.addObject("detail", detail);
//        mv.addObject("bankInfo", bankInfo);
////        mv.addObject("sysUser", sysUser);
//
//        // 判断 融资申请审核操作 页面 审核按钮隐藏（显示）
//        mv.addObject("applyState_Show_Hidden", apply_state);
//        mv.addObject("id", id);
//        mv.addObject("cfContractId", cf_contract_id);
//        return mv;
//    }




}
